package com.baizhi.service.impl;

import com.baizhi.dao.UserDao;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 野马 on 2019/6/17.
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public Map selectUser(String userName, int page, int rows) {
        //从第几条开始
        int start = (page-1)*rows;
        //每页显示几条
        int pageSize = rows;
        //模糊查询
        if(userName != null && !"".equals(userName)){
            userName = "%"+userName+"%";
        }else {
            userName = null;
        }
        int countUser = userDao.countUser(userName);
        List<User> userList = userDao.selectUser(userName, start, pageSize);

        /**
         * total和rows是固定写法
         */

        Map map = new HashMap();
        map.put("total",countUser);
        map.put("rows",userList);


        return map;
    }

    @Override
    public List<Map> selectGroupBySex() {
        List<Map> selectGroupBySex = userDao.selectGroupBySex();

        return selectGroupBySex;
    }

    @Override
    public List<Map> selectGroupBySF() {

        List<Map> selectGroupBySF = userDao.selectGroupBySF();
        return selectGroupBySF;
    }


}
